package com.bluewave.goaltracker;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.widget.LinearLayout;

import com.bluewave.goaltracker.utils.Goal;

public class MyPreferenceActivity extends PreferenceActivity implements
		OnSharedPreferenceChangeListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.addPreferencesFromResource(R.xml.preference);
		this.getPreferenceScreen().getSharedPreferences()
				.registerOnSharedPreferenceChangeListener(this);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	}

	/**
	 * used to change the summary of a preference
	 */
	public void onSharedPreferenceChanged(SharedPreferences sp, String key) {

		if(key.compareTo("daily_alert")==0||key.compareTo("alert_time")==0){
			Intent intent = new Intent("com.bluewave.AlarmBroadcastReceiver");
			intent.putExtra("alert_type", Goal.MONTHLY);

			sendBroadcast(intent);
		}
		else if(key.compareTo("not_used_alert")==0||key.compareTo("not_used_alert_time")==0){
			
			Intent intent = new Intent("com.bluewave.AlarmBroadcastReceiver");
			intent.putExtra("alert_type", Goal.NOT_USED_ALERT);

			sendBroadcast(intent);			
		}
	}
	
	private void loadColor(){
		SharedPreferences pres = PreferenceManager
		.getDefaultSharedPreferences(this);
		int backgroundColor = pres.getInt("background_color", 0);
		if(backgroundColor == 0) {
			return;
		}
	}
	
	public void onStart() {
		super.onStart();		
	}
	
	public void onStop() {
		super.onStop();
	}

}